package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.PageResult;
import com.woniu.pojo.Timetable;
import com.woniu.mapper.TimetableMapper;
import com.woniu.service.ITimetableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.vo.LeagueBookVo;
import com.woniu.vo.LeagueDetailVo;
import com.woniu.vo.TimetableQueryVo;
import com.woniu.vo.TimetableSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zbk
 * @since 2022-10-12
 */
@Service
public class TimetableServiceImpl extends ServiceImpl<TimetableMapper, Timetable> implements ITimetableService {

    @Autowired
    private TimetableMapper timetableMapper;

    /**
     * 搜索 + 分页
     * @param currentPage
     * @param pageSize
     * @param timetableQueryVo
     * @return
     */
    public PageResult search(Integer currentPage, Integer pageSize, TimetableQueryVo timetableQueryVo) {
        IPage iPage = new Page(currentPage, pageSize);
        IPage<Map<String, Object>> timetableIPage = timetableMapper.selectSearch(iPage, timetableQueryVo);
        PageResult pageResult = new PageResult(timetableIPage.getTotal(), timetableIPage.getRecords());

        return pageResult;
    }

    @Override
    public List<TimetableSearchVo> queryAll(String gymId) {
        List<TimetableSearchVo> timetableSearchVoList = timetableMapper.selectAll(gymId);
        for (TimetableSearchVo timetableSearchVo : timetableSearchVoList) {
            String label = timetableSearchVo.getLabel();
            String[] split = label.split(",");
            timetableSearchVo.setDynamicTags(split);
        }
        return timetableSearchVoList;
    }

    @Override
    public LeagueDetailVo detail(String id) {
        LeagueDetailVo leagueDetailVo = timetableMapper.detail(id);
        String label = leagueDetailVo.getLabel();
        String[] split = label.split(",");
        leagueDetailVo.setDynamicTags(split);
        return leagueDetailVo;
    }

    @Override
    public LeagueBookVo bookMsg(String id) {
        return timetableMapper.bookMsg(id);

    }
}
